package com.lm.action.plane;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.lm.entity.bean.PlaneChildrenOrder;
import com.lm.entity.vo.plane.PlaneOrderVO;
import com.lm.framework.adapater.LmBaseAction;
import com.lm.services.iface.plane.IChildrenService;
import com.lm.services.iface.plane.IPlaneOrderService;
import com.lm.utils.Const;
import com.lm.utils.Tools;
import com.lm.utils.page.PageBean;

public class PlaneOrderDetailAction extends LmBaseAction {
	private IChildrenService cs;
	private IPlaneOrderService pos;
	private PlaneOrderVO vo = new PlaneOrderVO();
	private PlaneChildrenOrder children =new PlaneChildrenOrder();
	
	public PlaneChildrenOrder getChildren() {
		return children;
	}

	public void setChildren(PlaneChildrenOrder children) {
		this.children = children;
	}

	public PlaneOrderVO getVo() {
		return vo;
	}

	public void setVo(PlaneOrderVO vo) {
		this.vo = vo;
	}

	public IChildrenService getCs() {
		return cs;
	}

	public IPlaneOrderService getPos() {
		return pos;
	}

	public void setCs(IChildrenService cs) {
		this.cs = cs;
	}
	
	public void setPos(IPlaneOrderService pos) {
		this.pos = pos;
	}

	public String getObject(){
		vo = returnVo();
		return Const.SUCCESS;
	}
	
	private PlaneOrderVO returnVo(){
		HttpServletRequest request = ServletActionContext.getRequest();
		vo.setId(Integer.parseInt(request.getParameter("cid")));
		vo.setItinerary(null);
		vo.setChildrenOrders(null);
		vo.setChildrenOrder(null);
		vo = pos.getPlaneOrderVo(vo);
		return vo;
	}
	
	public String updateOrder(){
		try {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		PlaneChildrenOrder childOrder = (PlaneChildrenOrder)cs.getObject(Integer.valueOf(request.getParameter("pid")));
//		cs.updateOrder(childOrder);
		response.getWriter().print("0");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public String childrenList(){
		
		PageBean pageBean = getPageBean();
		
		pageBean.setShowPageToolsMenu(true);
		
		pageBean.setSort("DESC");
		HttpServletRequest request = ServletActionContext.getRequest();
		if(Tools.isNotNullOrEmpty(children.getDecription())){
			switch (Integer.valueOf(children.getTitle())) {
			case 1:
				children.setPnrno(children.getDecription());
				break;
			}
		}
		
		List<PlaneChildrenOrder> orders= cs.getList(children, pageBean);
		
		request.setAttribute("orders", orders);
		
		request.setAttribute("pageBean", pageBean);
		
		return "list";
		
	}

}
